<?php if(!$this->is_ajax_request){ ?>
<?php if($this->instance_count == 1 && !Xcrud_config::$disable_plugins){ ?>
<?php if(!$this->disable_jquery_ui){ ?><link href="<?php echo $this->crud_url?>/plugins/jquery-ui/jquery-ui-1.9.1.custom.min.css" rel="stylesheet" type="text/css" /><?php } ?>
<link href="<?php echo $this->crud_url?>/plugins/timepicker/jquery-ui-timepicker-addon.css" rel="stylesheet" type="text/css" />
<link href="<?php echo $this->crud_url?>/themes/<?php echo $this->theme?>/xcrud.css" rel="stylesheet" type="text/css" />
<?php } ?>
<div class="xcrud">
    <h1 class="xcrud-header">
        <a class="xcrud-toggle<?php echo ($this->start_minimized)? ' closed' : ''?>" href="javascript:void(0);"></a>
        <?php echo $this->table_name?>
    </h1>
    <div class="xcrud-container"<?php echo ($this->start_minimized)? ' style="display:none;"' : ''?>>
<?php } ?>
        <div class="xcrud-ajax">
        <?php if($this->is_add or $this->is_csv or $this->is_print){ 
            if($this->is_csv){ ?>
            <form class="xcrud-csv-export" method="post" target="_blank" action="<?php echo $this->crud_url?>/xcrud_csv.php" accept-charset="<?php echo Xcrud_config::$dbencoding?>">
            <?php } ?>
        <div class="xcrud-top-actions">
            <?php if($this->is_csv){ ?>
                <button type="submit" class="xcrud-action-button xcrud-csv" >Export into CSV</button>
            <?php }
            if($this->is_print){ ?>
                <a class="xcrud-print xcrud-action-button" href="javascript:void(0);" onclick="jQuery.print_window(window.open('', 'Print','height=460,width=760'),jQuery(this).closest('.xcrud-ajax'));">Print</a>
            <?php }
            if($this->is_add){ ?>
            <a class="xcrud-add xcrud-action-button" href="javascript:void(0);">Add</a>
            <?php } 
            if(Xcrud_config::$top_pagination){ echo $pagination; } ?>
        </div>
        <?php } ?>
        <div class="xcrud-list-container">
        <table class="xcrud-list">
            <thead>
            <tr class="xcrud-th">
                <th class="xcrud-num">&#35;</th>
                <?php
                foreach($this->columns_names as $field=>$title){
                    if(isset($this->field_type[$field]) && $this->field_type[$field] == 'password') continue;
                    echo '<th';
                    $primary = $this->primary == $field ? ' primary' : '';
                    echo ($order_column == $field) ? ' class="xcrud-column xcrud-current '.$order_direct.$primary.'"' : ' class="xcrud-column'.$primary.'"';
                    echo ' data-order-dir="' . ($order_column == $field ? ($order_direct=='asc' ? 'desc' : 'asc') : $order_direct).'"';
                    echo ' data-column="'.$field.'"';
                    echo '>';
                    echo ($order_column == $field ? ($order_direct=='asc' ? '&uarr; ' : '&darr; ') : '') . $title;
                    echo '</th>';
                }
                if($this->is_edit || $this->is_remove || $this->buttons)
                    echo '<th class="xcrud-actions">&nbsp;</th>';
                ?>
            </tr>
            </thead>
            <tbody>
            <?php $i=0;
            if($list){
            foreach($list as $key=>$row){
                echo '<tr class="xcrud-row-'.$i.'">';
                echo '<td class="xcrud-num">'.($key+$start+1).'</td>';
                foreach($row as $field=>$value){
                    if($field == 'primary_key' or (isset($this->field_type[$field]) && $this->field_type[$field] == 'password')) continue;
                    echo '<td';
                    if($order_column == $field) echo ' class="xcrud-current"';
                    echo '>';
                    echo $this->_render_list_item($field, $value, $row->primary_key);
                    echo '</td>';
                }
                if($this->is_edit || $this->is_remove || $this->buttons){
                    echo '<td class="xcrud-actions'.(Xcrud_config::$fixed_action_buttons?' xcrud-fix':'').'">';
                    //echo $this->is_duplicate ? '<a class="xcrud-clone" data-primary="'.($row->primary_key).'" title="Duplicate" href="javascript:void(0);"></a>' : '';
                    //echo $this->is_edit ? ' <a class="xcrud-edit" data-primary="'.($row->primary_key).'" title="Edit" href="javascript:void(0);"></a>' : '';
                    //echo $this->is_remove ? ' <a class="xcrud-remove'.($this->remove_confirm ? ' xcrud-confirm' : '').'" data-primary="'.($row->primary_key).'" title="Remove" href="javascript:void(0);"></a>' : '';
                    echo $this->_render_list_buttons($row);
                    echo '</td>';
                }
                echo '</tr>';
                $i = 1-$i;
            }
            }else{
                echo '<tr class="xcrud-row-'.$i.'"><td colspan="'.(count($this->columns_names)+2).'">Entries not found.</td></tr>';
            }
            ?>
            </tbody>
            <?php
            if($this->sum){ ?>
            <tfoot>
            <tr class="xcrud-th">
                <td class="xcrud-num xcrud-sum">&Sigma;</td>
                <?php
                foreach($this->columns_names as $field=>$title){
                    if(isset($this->field_type[$field]) && $this->field_type[$field] == 'password') continue;
                    echo '<td';
                    $primary = $this->primary == $field ? ' primary' : '';
                    echo ($order_column == $field) ? ' class="xcrud-current xcrud-sum"' : ' class="xcrud-sum"';
                    echo '>';
                    echo (isset($this->sum_row->$field) ? $this->_render_list_item($field, $this->sum_row->$field, 0) : '&nbsp;');
                    echo '</td>';
                }
                if($this->is_edit || $this->is_remove || $this->buttons)
                    echo '<td class="xcrud-sum">&nbsp;</td>';
                ?>
            </tr>
            </tfoot>
            <?php }
            ?>
        </table>
        </div>
        <div class="xcrud-nav">
            <select class="xcrud-limit-list input-mini">
                <?php
                if(!in_array($this->limit,$this->limit_list)){
                    $this->limit_list = array_merge(array($this->limit),$this->limit_list);
                }
                foreach($this->limit_list as $limts){
                    echo '<option value="'.$limts.'"'.($limts==$limit?' selected="selected"':'').'>'.$limts.'</option>';
                }
                ?>
            </select>
            <?php echo $pagination?>
            <?php if($this->is_search){ ?>
            <?php echo (!$phrase && !Xcrud_config::$search_opened) ? '<a class="xcrud-search-toggle xcrud-action-button" href="javascript:void(0);">Search</a>' : ''?>
            <span class="xcrud-search"<?php echo (!$phrase && !Xcrud_config::$search_opened) ? ' style="display:none;"' : ''?>>
                <input type="text" class="xcrud-data xcrud-phrase" name="phrase" value="<?php echo $phrase?>" />
                <select class="xcrud-data" name="column">
                    <?php
                    foreach($this->columns_names as $field=>$title){
                        echo '<option value="'.$field.'"'.($field==$column?' selected="selected"':'').'>'.$title.'</option>';
                      }
                    ?>
                </select>
                <a class="xcrud-search-go xcrud-action-button" href="javascript:void(0);">Go</a>
                <?php echo ($phrase) ? '<a class="xcrud-search-reset xcrud-action-button" href="javascript:void(0);">Reset</a>' : ''?>
            </span>
            <?php } ?>
            <span class="xcrud-benchmark"><?php echo $this->benchmark_end()?></span>
            <input type="hidden" class="xcrud-data" name="key" value="<?php echo $this->key?>" />
            <input type="hidden" class="xcrud-data" name="order" value="<?php echo $order_column?>" />
            <input type="hidden" class="xcrud-data" name="direct" value="<?php echo $order_direct?>" />
            <input type="hidden" class="xcrud-data" name="start" value="<?php echo $start?>" />
            <input type="hidden" class="xcrud-data" name="limit" value="<?php echo $limit?>" />
            <input type="hidden" class="xcrud-data" name="instance" value="<?php echo $this->instance_name()?>" />
            <input type="hidden" class="xcrud-data" name="task" value="list" />
            <?php if(Xcrud_config::$dynamic_session) { ?>
            <input type="hidden" class="xcrud-data" name="sess_name" value="<?php echo $this->sess_name?>" />
            <?php } ?>
        </div>
        
        <?php if($this->is_csv){ ?>
            </form>
        <?php } ?>
        
        <div class="xcrud-overlay"></div>
        </div>
<?php if(!$this->is_ajax_request){ ?>
    </div>
</div>
<?php if($this->instance_count == 1){ ?>
<script type="text/javascript">
<!--

	var xcrud_url = '<?php echo $this->crud_url?>'; var tinymce_init_url = '<?php echo $this->tinymce_init_url?>';
    <?php echo ($this->tinymce_folder_url or $this->force_tinymce) ? 'var tinymce_init=1;' : 'var tinymce_init=0;' ?>
    <?php echo $this->jquery_no_conflict ? 'jQuery.noConflict(); ' : ''?>var imgurl = ''; 
    
-->
</script>
<?php } ?>
<?php if($this->instance_count == 1 && !Xcrud_config::$disable_plugins){ ?>
<?php if(!$this->disable_jquery){ ?><script src="<?php echo $this->crud_url?>/plugins/jquery-1.8.2.min.js"></script><?php } ?>
<?php if(!$this->disable_jquery_ui){ ?><script src="<?php echo $this->crud_url?>/plugins/jquery-ui/jquery-ui-1.9.1.custom.min.js"></script><?php }  ?>

<script src="<?php echo $this->crud_url?>/plugins/timepicker/jquery-ui-timepicker-addon.js"></script>
<?php if($this->tinymce_folder_url){ ?><script src="<?php echo $this->tinymce_folder_url?>/tiny_mce.js"></script><?php } ?>
<script src="<?php echo $this->crud_url?>/plugins/xcrud.js"></script>
<?php } ?>
<?php } ?>